<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <script>
        // （26)现在有一段字符串，要求统计字符串总出现的字符和次数
        let str = 'ashdkahsfukaysduiqewke'
        // 字符串也有下标和长度,可以使用for进行遍历
        let obj = {}
        for (let i = 0; i < str.length; i++) {
            // 第一次出现的时候,将对象的值赋值为1
            if(!obj[str[i]]){
                obj[str[i]] = 1
            }else{
                // 存在就让数量加1
                obj[str[i]]++
            }
            // 方案二
            // 用当前字符进行分隔
            // obj[str[i]] = str.split(str[i]).length - 1
            
        }
        console.log(obj)

        // (27) 2.请用最优方法输出长度为500的数组内容为：["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "AA", "AB", "AC", "AD", "AE", "AF", "AG", "AH", "AI", "AJ", "AK", "AL", "AM", "AN", "AO", "AP", "AQ", "AR", "AS", "AT", "AU", "AV", "AW", "AX", "AY", "AZ", "BA", "BB", "BC", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BK", "BL", "BM", "BN", "BO", "BP", "BQ", "BR", "BS", "BT", "BU", "BV", "BW", "BX", "BY", "BZ", "CA", "CB"]...	根据字符编码65——91对应了A——Z，以下函数可以获得一个[A,B,C...Y,Z]数组
        function getEN() {
            var arr = [];

            for (var i = 65; i < 91; i++) {
                arr.push(String.fromCharCode(i));
            }

            return arr;
        }
        const newArr = getEN()
        const sumArr = function () {
            const resArr = []
            for (let i = 0; i < 500; i++) {
                let str = ''
                if (i < 26) {
                    resArr.push(newArr[i])
                } else {
                    //当i >= 26 是 通过 i / 26 取整减一得到第一个字母  第二个字母通过取余获得
                    str = newArr[parseInt(i / 26) - 1] + newArr[i % 26]
                    resArr.push(str)
                }

            }
            return resArr
        }
        console.log(sumArr())


        // (28)数组扁平化 let arr = [1, 2, 3, [4, 5, [6, 7, [8, 9]]]]，将数组arr转变成[1,2,3,4,5,6,7,8,9]
        let arr = [1, 2, 3, [4, 5, [6, 7, [8, 9]]]]
        function resArr(oldArr){
            let newArr = []
            for(k in oldArr){
                if(oldArr[k] instanceof Array){
                    // newArr.push(...resArr(oldArr[k]))
                    newArr = newArr.concat(resArr(oldArr[k]))
                }else {
                    newArr.push(oldArr[k])
                }
            }
            return newArr
        }
        console.log(resArr(arr))
        // 方案二
        const newArr1 = arr.flat(3)
        console.log(newArr1)
    </script>
</body>
</html>
